define(function(require){
	var $=require("jq");
	var Dialog=require("pz_use_dialog.js");

		$('#mobilePhone').blur(function(){
			var v=this.value;
			
			if(v.isMobile()){
				$(this).attr("isok","yes");
			}else{
				$(this).attr("isok","no");
			};
			
		});
	  	//保存Tab1的内容
	  	$('#saveTab1').on('click',function(event){
	  		var user_id = $('#user_id').val();
	  		var realName = $('#realName').val();
	  		var nickName = $('#nickName').val();
	  		var gender = $('.chooseSex:checked').val();
//	  		var mobilePhone = $('#mobilePhone').val();
	  		var idCardType = $('#idCardType').val();
	  		var idCardNum = $('#cardNum').val();
	  		var provinceId = $('#provinceId').val();
	  		var cityId = $('#cityId').val();
	  		var areaId = $('#areaId').val();
	  		var address = $('#address').val();
	  		var qqNumber = $('#qqNumber').val();
	  		var msnNumber = $('#msnNumber').val();
	  		var parentName = $('#parentName').val();
	  		var param = {
  					"user_id":user_id,
  					"realName":realName,
  					"nickName":nickName,
  					"gender":gender,
//  					"mobilePhone":mobilePhone,
  					"idCardType":idCardType,
  					"idCardNum":idCardNum,
  					"provinceId":provinceId,
  					"cityId":cityId,
  					"areaId":areaId,
  					"address":address,
  					"qqNumber":qqNumber,
  					"msnNumber":msnNumber,
  					"parentName":parentName,
  					"act":"tab1"};
	  		
//	  		if($('#mobilePhone').attr("isok")!="yes"){
//	  			
//	  			var tips=new PZ_Dialog({
//					  type:"alert",
//					  text:"提示",
//					  tipsText:"<p style='text-align:center;'>手机号格式不对</p>",
//					  buttonSureText:"知道了", 
//					  mask:0.3,
//					  isDrag:true               //开起拖动
//					  });
//	  			return false;
//	  		};
	  		$.post("/vipCenter/updateUserData.do",param,function(data){
	  			var ss =data.success;
	  			if(data.success == 'ok'){
	  				var tips=new Dialog({
						  type:"alert",
						  text:"提示",
						  tipsText:"更新成功",
						  callBack:function(){
								window.location.href = "/vipCenter/completeUserData.do?menu_id=3";  
						  },
						  mask:0.3
						  });
	  				return;
	  			}else{
	  				var tips=new Dialog({
						  type:"alert",
						  text:"提示",
						  tipsText:data.msg,
						  mask:0.3
						  });
	  			}
	  		},"json");
	  	});


//修改密码

	  	$('#oldPwd').blur(function(event) {
			var oldPwdVal = oldPwd.value;
			var reg = /(^\s+)|(\s+$)/g;
			if(!oldPwdVal.Trim().isPassword() || reg.test(oldPwdVal)){
				$(this).next().html("密码由6到16位字母和数字组成！").show().removeClass("ok").addClass("tips");
				return;
			}
			else{
				$(this).next().html("").show().removeClass("tips").addClass("ok");
			}
		});

		$('#newPwd').blur(function(event) {
			
			var newPwdVal = newPwd.value;
			var reg = /(^\s+)|(\s+$)/g;
			if(!newPwdVal.Trim().isPassword() || reg.test(newPwdVal)){
				$(this).next().html("密码由6到16位字母和数字组成！").show().removeClass("ok").addClass("tips");
				return
			}

			else{
				$(this).next().html("").removeClass("tips").addClass("ok");
			}
		})

		$('#newTwoPwd').blur(function(event) {
			var reg = /(^\s+)|(\s+$)/g;
			var newTwoPwdVal = newTwoPwd.value;

			var newPwdVal = newPwd.value;

			if(!newPwdVal.Trim().isPassword()||newPwdVal==""){
				$(this).next().removeClass("ok").addClass("tips");
				return
			}

			if (newTwoPwdVal!=newPwdVal) {

				$(this).next().html("两次密码输入不一致！").show().removeClass("ok").addClass("tips");
				return;
			}
			else{
				$(this).next().html("").removeClass("tips").addClass("ok");
			}
		})
		$("#checkStr").focus(function(){
			$("#checkStr").next(".validate-code-pic").find("span").hide();
		});
		//切换验证码click
		$('.validate-code-pic').click(function(){
			$("img",this).attr("src","/validateCode?random="+Math.random());
		});
		
		
		//保存tab2
		$('#saveTab2').on('click',function(event){
			var oldPwd = $('#oldPwd').val();
			var newPwd = $('#newPwd').val();
			var newTwoPwd = $('#newTwoPwd').val();
			var checkStr = $('#checkStr').val();


			if(!oldPwd.Trim().isPassword()){
				$('#oldPwd').blur();
				return
			}
			if(!newPwd.Trim().isPassword()){
				$('#newPwd').blur();
				return
			}
			if(!newTwoPwd.Trim().isPassword()){
				$('#newTwoPwd').blur();
				return
			}
			if(checkStr==""){
				$('#checkStr').blur();
				return
			}
			var param = {
  					"oldPassword":oldPwd,
  					"password":newPwd,
  					"confirmPassword":newTwoPwd,
  					"validateCode":checkStr
  					};
			
			$.post("/vipCenter/updatePassword.do",param,function(data){
	  			var ret =data.ret;
	  			if(ret == 1){
	  				var tips=new Dialog({
						  type:"alert",
						  text:"提示",
						  tipsText:"密码修改成功,请使用新密码重新登录！",
						  callBack:function(){
								window.location.href = "/login.do";  
						  },
						  mask:0.3
						  });
	  				return;
	  			}else if(ret == -2){
	  				var tips=new Dialog({
						  type:"alert",
						  text:"提示",
						  tipsText:data.msg,
						  callBack:function(){
								window.location.href = "/login.do?toUrl=/vipCenter/updatePassword.do";  
						  },
						  mask:0.3
						  });
	  				return;
	  			}else{
	  				if(ret == -3){
	  					$("#oldPwd").next().html(data.msg).show().removeClass("ok").addClass("tips");
	  				}else if(ret == -4){
	  					$("#newTwoPwd").next().html(data.msg).show().removeClass("ok").addClass("tips");
	  				}else if(ret == -5){
	  					$("#checkStr").next(".validate-code-pic").find("span").html(data.msg).show().removeClass("ok").addClass("tips");
	  					$("#checkStr").val('');
	  				}
	  				$(".validate-code-pic img").attr("src","/validateCode?random="+Math.random());
	  				return;
	  			}
	  		},"json");
		})


});